//
//  NewFriendCell.swift
//  YueChat
//
//  Created by IMac on 2024/9/21.
//

import UIKit

class NewFriendCell: UITableViewCell {

    @IBOutlet weak var staBtn: UIButton!
    @IBOutlet weak var subLab: UILabel!
    @IBOutlet weak var nameLab: UILabel!
    @IBOutlet weak var img: UIImageView!
    var info = DMCCRequest()
    var block:(() -> Void)?
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    @IBAction func action(_ sender: Any) {
        // 已添加不用回调
        if (self.info.status == OsnRequestStatus.Accepted) {
            return;
        }
        self.block!()
    }
    func setInfo(info:DMCCRequest) {
        self.info = info
        if info.type == OsnRequestType.Friend {
            let userInfo = gosnUser.getUserInfoDefault(info.from)
            nameLab.text = userInfo.getDisplayName()
            img.sd_setImage(with: URL(string: userInfo.portrait), placeholderImage: SDImageDefault)
            subLab.text = info.reason
            if info.status == OsnRequestStatus.Accepted {
                staBtn.setTitle(KLocalizedString("NewFriendAdded"), for: .normal)
                staBtn.backgroundColor = .clear
            } else {
                staBtn.setTitle(KLocalizedString("NewFriendAdd"), for: .normal)
                staBtn.backgroundColor = kGrayBG
            }

        } else {
            let userInfo = gosnUser.getUserInfoDefault(info.from)
            let groupInfo = gosnGroup.getGroupInfoDefault(info.group)
            nameLab.text = userInfo.getDisplayName()
            img.sd_setImage(with: URL(string: userInfo.portrait), placeholderImage: SDImageDefault)
            subLab.text = String(format: KLocalizedString("ApplyAddGroup"), userInfo.getDisplayName(), groupInfo.name)
            if info.status == OsnRequestStatus.Accepted {
                staBtn.setTitle(KLocalizedString("NewFriendAdded"), for: .normal)
                staBtn.backgroundColor = .clear
            } else {
                staBtn.setTitle(KLocalizedString("NewFriendAdd"), for: .normal)
                staBtn.backgroundColor = kGrayBG
            }

        }
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
